package com.example.demo.mvc;

import javafx.beans.binding.Bindings;

import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableStringValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.util.StringConverter;

public class EmploymentViewController {

    private static  final  Employment employment = new Employment("张三", "沈阳", 9999.0);



    @FXML
    TextField tf_name;

    @FXML
    TextField tf_position;

    @FXML
    TextField tf_annualSalary;

    @FXML
    public void initialize() {
        System.out.println(employment);
        tf_name.textProperty().bindBidirectional(employment.namePropertyProperty());
        tf_position.textProperty().bindBidirectional(employment.positionPropertyProperty());
        tf_annualSalary.textProperty().bindBidirectional(employment.annualSalaryPropertyProperty(),                new StringConverter<Number>() {
                    @Override
                    public String toString(Number object) {
                        return object.toString();
                    }

                    @Override
                    public Number fromString(String string) {
                        return  Double.parseDouble(string) ;
                    }
                });

    }

}
